//
//  UIViewController+NaviigationItem.m
//  TenThousand
//
//  Created by baixue on 16/7/5.
//  Copyright © 2016年 baixue. All rights reserved.
//

#import "UIViewController+NaviigationItem.h"

#import <objc/runtime.h>

@implementation UIViewController (NaviigationItem)

static char kLeftClickKey;
static char kRightClickKey;

-(void)createLeft:(UIImage *)leftimage leftClick:(NavigationClick)leftClick right:(UIImage *)rightimage rightClick:(NavigationClick)rightClick{
    
    if (leftimage) {
        self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:leftimage style:UIBarButtonItemStylePlain target:self action:@selector(leftButtonClick)];
        self.leftClick = leftClick;
    }
    
    if (rightimage) {
        self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:rightimage style:UIBarButtonItemStylePlain target:self action:@selector(rightButtonClick)];
        self.rightClick = rightClick;
    }
}






-(void)leftButtonClick{
    if (self.leftClick) {
        self.leftClick();
    }
    
}

-(void)rightButtonClick{
    
    if (self.rightClick) {
        self.rightClick();
    }
    
}

- (void)setLeftClick:(NavigationClick)leftClick{
    objc_setAssociatedObject(self, &kLeftClickKey, leftClick, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (NavigationClick)leftClick{
    return objc_getAssociatedObject(self, &kLeftClickKey);
}

- (void)setRightClick:(NavigationClick)rightClick{
    objc_setAssociatedObject(self, &kRightClickKey, rightClick, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (NavigationClick)rightClick{
    return objc_getAssociatedObject(self, &kRightClickKey);
}



@end

